<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <a href="#home">主页</a>
    <a href="#about">关于</a>
    <div class="routerView"></div>
</head>
<body>
    <script>
        let routes = [
            {
                path: '#home',
                components: '<h1>我是主页</h1>'
            },
            {
                path: '#about',
                components: '<h1>我是关于页</h1>'
            },
        ]
        let routerView = document.querySelector('.routerView')
        window.addEventListener('hashchange', e => {
            let hash = location.hash
            console.log(hash);
            routes.forEach(item => {
                if(item.path === hash) {
                    routerView.innerHTML = item.components
                }
            })
        })
    </script>
</body>
</html>